<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="医院名称">
        <el-input v-model="hospitalSet.hosname"/>
      </el-form-item>
      <el-form-item label="医院编号">
        <el-input v-model="hospitalSet.hoscode"/>
      </el-form-item>
      <el-form-item label="api基础路径">
        <el-input v-model="hospitalSet.apiUrl"/>
      </el-form-item>
      <el-form-item label="联系人姓名">
        <el-input v-model="hospitalSet.contactsName"/>
      </el-form-item>
      <el-form-item label="联系人手机">
        <el-input v-model="hospitalSet.contactsPhone"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate" v-if="hospitalSet.id">更新</el-button>
        <el-button type="primary" @click="saveOrUpdate" v-else>保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import hospSet from "../../api/hospSet";
export default {
  name: "Add",
  data(){
    return {
      hospitalSet:{
        hosname: '',
        hoscode: '',
        apiUrl: '',
        contactsName: '',
        contactsPhone: ''
      }
    }
  },
  methods:{
    save(){
      hospSet.addHospSet(this.hospitalSet).then(resp =>{
        this.$message.success("添加医院设置成功");
        this.$router.push("/hospSet/list");
      })
    },
    update(){
      hospSet.updateHospSet(this.hospitalSet).then(resp =>{
        this.$message.success("修改医院设置成功");
        this.$router.push("/hospSet/list");
      })
    },
    saveOrUpdate(){
      if (this.hospitalSet.id){
        this.update();
      }else {
        this.save();
      }
    },
    getHospSetById(id){
      hospSet.getHospSetById(id).then(resp =>{
        this.hospitalSet = resp.data;
      })
    }
  },
  created() {
    if (this.$route.params.id){
      this.getHospSetById(this.$route.params.id)
    } else {
      this.hospitalSet = {}
    }
  }
}
</script>

<style scoped>

</style>
